#ifndef VIDEOWIDGET_H
#define VIDEOWIDGET_H
#include <QPainter>
#include <QWidget>
#include <atomic>
#include <memory>
#include <mutex>
#include <thread>

class FfmVideoReader;
template <class T>
class Tensor;

class VideoWidget : public QWidget {
    Q_OBJECT
   public:
    explicit VideoWidget(QWidget* parent = nullptr);
    ~VideoWidget();
    void open(const char* videoPath);
    void stop();

    int videoWidth;
    int videoHeight;

   protected:
    // void setImage(std::shared_ptr<Tensor<uint8_t>> imgPtr);
    void setRects(QVector<QRect>& rects);
    void paintEvent(QPaintEvent* event) override;
    Q_INVOKABLE void refresh();

   signals:

   private:
    int i = 0;
    std::string path_;
    QImage image_;
    QVector<QRect> rects_;
    std::mutex rectMutex_;

    FfmVideoReader* videoReader_ = nullptr;
    std::thread* widgetTh_ = nullptr;
    bool isPlaying = false;
};

#endif  // VIDEOWIDGET_H
